package name.matthewgreet.example12.action; import java.util.Arrays; import org.apache.struts2.ActionSupport; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.InterceptorRef; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; import org.apache.struts2.interceptor.validation.SkipValidation; import com.opensymphony.xwork2.validator.annotations.ConversionErrorFieldValidator; import com.opensymphony.xwork2.validator.annotations.CustomValidator; /** * Struts 2 Action for testing fixed array with parameters submitted with indices. */ @InterceptorRef("defaultStack") @Results({ @Result(name=ActionSupport.ERROR, location="/pages/StaticIndexedToArray.jsp"), @Result(name=ActionSupport.INPUT, location="/pages/StaticIndexedToArray.jsp"), @Result(name=ActionSupport.SUCCESS, location="/pages/StaticIndexedToArray.jsp") }) public class StaticIndexedToArrayAction extends ActionSupport { private static final long serialVersionUID = -6084392315736424463L; private int[] year = new int[5]; private String resultText; @Action("/StaticIndexedToArray") @Override @SkipValidation public String execute() throws Exception { return SUCCESS; } @Action("/StaticIndexedToArray_submit") public String submit() throws Exception { try { resultText = "Years are " + Arrays.toString(year); return SUCCESS; } catch (Exception e) { System.out.println("Action failed reason=" + e.getMessage()); return ERROR; } } @CustomValidator(type="requiredEntry", message="Year is required", shortCircuit = true) @ConversionErrorFieldValidator(message = "Year must be a whole number", repopulateField = true, shortCircuit = true) public int[] getYear() { return year; } public void setYear(int[] year) { this.year = year; } public String getResultText() { return resultText; } }